#ifndef _ICAR_H
#define _ICAR_H

#if defined(__cplusplus)
extern "C" {
#endif

#include <arpa/inet.h>

#ifdef HAVE_NLS
# define _(string)	gettext (string)
#else
# define _(string)	string
#endif

#define progname	_("icar")

#define MAX_PKG_LENGTH		1040		/* 最大的数据包长度，包括校验码，不包括0x7e头和0x7e尾 */
#define MAX_BODY_LENGTH		1023		/* 最大的消息体长度 */

#define ICAR_END_RESPONSE	0x0001	/* 终端通用应答 */
#define ICAR_END_HEARTBEAT	0x0002	/* 终端心跳 */
#define ICAR_END_REGISTER	0x0100	/* 终端注册 */
#define ICAR_END_UNREGISTER	0x0003	/* 终端注销 */
#define ICAR_END_AUTHENTICATE	0x0102	/* 终端鉴权 */
#define ICAR_END_PARAM_RESPONSE	0x0104	/* 查询终端参数应答 */
#define ICAR_END_PROPERY_RES	0x0107	/* 查询终端属性应答 */
#define ICAR_END_UPGRADE_NOTICE	0x0108	/* 终端升级结果通知 */
#define ICAR_END_LOCALINFO_REPORT	0x0200 /* 位置信息汇报 */
#define ICAR_END_LOCALINFO_RESPONSE	0x0201	/* 位置信息查询应答 */
#define ICAR_END_EVENT_REPORT		0x0301 	/* 事件报告 */
#define ICAR_END_ASK_RESPONSE		0x0302	/* 提问应答 */
#define ICAR_END_INFO_HELPMENU_CANCLE	0x0303	/* 信息点播/取消 */
#define ICAR_END_VEICHLE_CTL_RESPONSE	0x0500	/* 车辆控制应答 */
#define ICAR_END_DATA_RECORDER_UPLOAD	0x0700 	/* 行驶记录仪数据上传 */
#define ICAR_END_ELEC_WAYBILL_REPORT	0x0701	/* 电子运单上报 */
#define ICAR_END_DRIVER_IDINFO_REPORT	0x0702	/* 驾驶员身份信息采集上报 */
#define ICAR_END_LOCALDATA_BULK_UPLOAD	0x0704	/* 定位数据批量上传 */
#define ICAR_END_CAN_DATA_UPLOAD		0x0705	/* CAN 总线数据上传 */
#define ICAR_END_MULTMEDIA_EVENT_UPLOAD	0x0800	/* 多媒体事件信息上传 */
#define ICAR_END_MULTMEDIA_DATA_UPLOAD	0x0801	/* 多媒体数据上传 */
#define ICAR_END_CAMERA_FILM_RESPONSE	0x0805	/* 摄像头立即拍摄命令应答 */
#define ICAR_END_STORE_MULTMEDIA_CHECK_RESPONSE	0x0802	/* 存储多媒体数据检索应答 */
#define ICAR_END_DATA_UPLINK_TRANSMISSON	0x0900	/* 数据上行透传 */
#define ICAR_END_DATA_COMPRESS_REPORT		0x0901	/* 数据压缩上报 */
#define ICAR_END_RSA_ENCRYPT			0x0A00	/* 终端RSA公钥 */



#define ICAR_FLAT_RESPONSE		0x8001	/* 平台通用应答 */
#define ICAR_SUPPLEMENT_REQUEST	0x8003	/* 补传分包请求 */
#define ICAR_FLAT_REGISTER_RES	0x8100	/* 终端注册应答 */
#define ICAR_SET_END_PARAM		0x8103	/* 设置终端参数 */
#define ICAR_GET_END_PARAM		0x8104	/* 查询终端参数 */
#define ICAR_END_CONTROL		0x8105	/* 终端控制 */
#define ICAR_GET_SPEC_END_PARAM	0x8106	/* 查询指定终端参数 */
#define ICAR_GET_END_PROPERTY	0x8107	/* 查询终端属性 */
#define ICAR_ISSUE_END_UPGRADE	0x8108	/* 下发终端升级包 */
#define ICAR_GET_LOCALINFO		0x8201	/* 位置信息查询 */
#define ICAR_TEMP_LOCAL_CONTROL	0x8202	/* 临时位置跟踪控制 */
#define ICAR_MANUAL_CONFIRM_ALARM	0x8203	/* 人工确认报警信息 */
#define ICAR_TEXT_INFO_ISSUE	0x8300	/* 文本信息下发 */
#define ICAR_FLAT_EVENT_SET			0x8301	/* 事件设置 */
#define ICAR_FLAT_ASK_ISSUE		0x8302	/* 提问下发 */
#define ICAR_INFO_HELPMENU_SET	0x8303	/* 信息点播菜单设置 */
#define ICAR_INFO_SERVICE		0x8304	/* 信息服务 */
#define ICAR_PHONE_CALLBACK		0x8400	/* 电话回拨 */
#define ICAR_SET_PHONEBOOK		0x8401	/* 设置电话本 */
#define ICAR_VEICHLE_CONTROL	0x8500	/* 车辆控制 */
#define ICAR_SET_CYCLE_AREA		0x8600	/* 设置圆形区域 */
#define ICAR_DEL_CYCLE_AREA		0x8601	/* 删除圆形区域 */
#define ICAR_SET_RECTANGLE_AREA	0x8602	/* 设置矩形区域 */
#define ICAR_DEL_RECTANGLE_AREA	0x8603	/* 删除矩形区域 */
#define ICAR_SET_POLYGON_AREA	0x8604	/* 设置多边形区域 */
#define ICAR_DEL_POLYGON_AREA	0x8605	/* 删除多边形区域 */
#define ICAR_SET_ROUTINE		0x8606	/* 设置路线 */
#define ICAR_DEL_ROUTINE		0x8607	/* 删除路线 */
#define ICAR_DATA_RECORDER_COLLECT	0x8700 /* 行驶记录仪数据采集命令 */
#define ICAR_RECORDER_PARAM_ISSUE	0x8701	/* 行驶记录仪参数下传命令 */
#define ICAR_REPORT_DRIVER_INFO_REQUEST	0x8702	/* 上报驾驶员身份信息请求 */
#define ICAR_MULTIMEDIA_UPLOAD_RESPONSE	0x8800	/* 多媒体数据上传应答 */
#define ICAR_CAMERA_FILM_CMD	0x8801	/* 摄像头立即拍摄命令 */
#define ICAR_STORE_MULTIMEDIA_CHECK	0x8802	/* 存储多媒体数据检索 */
#define ICAR_STORE_MULTIMEDIA_UPLOAD	0x8803	/* 存储多媒体数据上传 */
#define ICAR_RECORD_START_CMD	0x8804	/* 录音开始命令 */
#define ICAR_SINGLE_RETRIEVE_UPLOAD	0x8805 /* 单条存储多媒体数据检索上传命令 */
#define ICAR_DATA_DOWNLINK_TRANSMISSION	0x8900	/* 数据下行透传 */
#define ICAR_FLAT_RSA_ENCRYPT	0x8A00	/* 平台RSA公钥 */



#define VEHICLE_OFFSET_ALARM        0x01000000
#define VEHICLE_OIL_CUT_OFF         0x08000000
#define VEHICLE_BATTERY_REMOVE_ALARM    0x10000000
#define VEHICLE_BRACKES             0x20000000
#define VEHICLE_ACCERLATION         0x40000000
#define VEHICLE_ADD_REPORT          0x00020000
#define VEHICLE_POWER_BY_BACKUP_BATTERY 0x00040000
#define VEHICLE_BETTERY_REMOVED     0x00100000

#define VEHICLE_DOOR_OPEN           0x0100
#define VEHICLE_SET_DEFENCE         0x0200
#define VEHICLE_ACC_ON              0x0400
#define VEHICLE_SET_OFFSET_ALARM    0x0800
#define VEHICLE_CUSTOM_ALARM        0x4000
#define VEHICLE_OVERSPEED           0x8000

#define VEHICLE_STEAL_ALARM         0x01
#define VEHICLE_OVERSPEED_ALARM     0x04
#define VEHICLE_ILLEGAL_IGNITION    0x08

#define ALARM_VIBRATION_MAIL        0x1     /* 振动短信报警开 */
#define ALARM_VIBRATION_PHONE       0x2     /* 振动电话报警开 */
#define ALARM_POWEROFF_MAIL         0x4
#define ALARM_POWEROFF_PHONE        0x8
#define ALARM_TRUN_SIDE_MAIL        0x10
#define ALARM_TRUN_SIDE_PHONE       0x20
#define ALARM_OVERSPEED_MAIL        0x40
#define ALARM_OVERSPEED_PHONE       0x80


#define ALARM_OFFSET_MAIL           0x1
#define ALARM_OFFSET_PHONE          0x2
#define ALARM_ILLEGAL_START_MAIL    0x4
#define ALARM_ILLEGAL_START_PHONE   0x8
#define ALARM_LOW_POWER_MAIL        0x10
#define ALARM_LOW_POWER_PHONE       0x20

#define USER_ALARM_LOW_POWER        0x1
#define USER_ALARM_VIBRATE          0x2
#define USER_ALARM_DATA_STATUS      0x4
#define USER_ALARM_OBD              0x8
#define USER_ALARM_WATER_TERMPERATURE   0x10
#define USER_ALARM_ENGINE_OVERTIME      0x20
#define USER_ALARM_OVERSPEED            0x40
#define USER_ALARM_LOW_PRESSURE         0x80

#define BETTERY_LEVEL_IS_TRUN_SIDE      (1 << 7) /* 0 表示侧翻 */
#define BETTERY_LEVEL_IS_COLLISION      (1 << 6) /* 0 表示碰撞 */

#define EXTEND_NO_DATA          0x00    /* 基本定位数据，无扩展数据字段 */
#define EXTEND_OBD_DATA         0x01    /* 基本定位数据＋OBD数据（扩展数据） */
#define EXTEND_FAULT_DATA       0x02    /* 基本定位数据＋故障码 （扩展数据） */

#define VALUE_LEN	30



#define ICAR_HTONS(p)	do { \
				stmp = htons(p); \
				memcpy(&data[n], &stmp, 2); \
				n += 2;\
				}while (0);

#define ICAR_HTONL(p)	do { \
				ltmp = htonl(p);	\
				memcpy(&data[n], &ltmp, 4); \
				n += 4; \
				} while (0);

#if defined(__cplusplus)
}
#endif

#endif
